package com.solcoo.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.apache.log4j.Logger;
import com.solcoo.task.RewardTask;

// 九九数字充值
public class JJCZUtil {
	
	private static Logger logger = Logger.getLogger(RewardTask.class);
	
	public static String partner = "11435";
	public static String key = "vjDIbtRaveMrJqyuMPY8IV1eBV00EhnDAnt2Aipc6VgKkE9Ki1OxINa0wCye7lLL";
	public static String type = "0";
	public static String notify_url = "http://42.120.7.37/Solcoo/jjhuafeiCallback.jspDo";
	
	public String jjcz(String mobile, String value, String out_trade_id) {
		try {
			logger.error("JJCZUtil:mobile==" + mobile + "; value==" + value + "; out_trade_id==" + out_trade_id);
			String params = "partner=" + partner + "&out_trade_id=" + out_trade_id + "&mobile=" + mobile
					+ "&value=" + value + "&type="+type+"&notify_url=" + notify_url + "&";
			String sign = MD5Util.getMD5Encoding(params + key);
			String u = "http://api.99huafei.com/mobile/direct.aspx?" + params + "sign=" + sign;
			URL url = new URL(u);
			HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
			httpCon.connect();
			BufferedReader in = new BufferedReader(new InputStreamReader(httpCon.getInputStream()));
			String line = in.readLine();
			logger.error("JJCZUtil:out_trade_id=="+out_trade_id+"; result==" + line);
			return line;
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return "error";
		}
	}
}
